<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.resourcemanagement.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.add.title") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.ip") %></label>
						<span><input type="text" id="ip" name="ip" maxlength="16" size="22" class="validate[required,custom[ipv4]]" /></span>
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.port") %></label>
						<span><input type="text" id="port" name="port" maxlength="16" size="22" class="validate[required,custom[integer]]" value="3306"/></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.username") %></label>
						<span><input type="text" id="username" name="username" maxlength="16" size="22" class="validate[required]" value="root"/></span>
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.password") %></label>
						<span><input type="text" id="password" name="password" maxlength="16" size="22" class="validate[required]" /></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.totalconn") %></label>
						<span><input type="text" id="totalconn" name="totalconn" maxlength="16" size="22" class="validate[required,custom[integer]]" value="5"/></span>
					</li>
				</ul>
       	 	</div>
       	 	<div class="button-group">
       	 		<input type="hidden" id="isCommon" name="isCommon" value='' />
       	 		<input type="button" class="btn btn-default" id="butCommon" name="butCommon" value='<%=MessageResourcesUtils.getMessage(request, "common.button.common") %>' />
       			<input type="button" class="btn btn-default" id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
       			<input type="button" class="btn btn-default" id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
		</div>
	</div>
</form>

<script type="text/javascript">	
$(document).ready(function() {
	
	$('#butSave').click(function() {
			var exp = $('#form1').validationEngine('validate');
			
			if(exp==true)
			{
				var isCommon = $('#isCommon').val();
				if(isCommon == ''){
					alert('<%=MessageResourcesUtils.getMessage(request, "alertinfo.databaseresource.java.alert3")%>')
				}else if(isCommon == '0'){
					alert('<%=MessageResourcesUtils.getMessage(request, "alertinfo.databaseresource.java.alert4")%>')
				}else if(isCommon == '1'){
					$.ajax({
						type: 'POST',
					    url: '${systemctx}/systemmanage/databaseresource/valiDatabaseResource.json',
					    data: $("#form1").serialize(),
					    dataType: 'json',
					    success: function(data)
					    {
					    	//关闭执行...
							//closeSending();
					    	if (data.messagetype == '2')
					    	{
					    		//显示AJAX请求后的提示信息
								$.fn.ajaxmessage(data);
					    	}
					    	else
					    	{
					    		form1.action="${systemctx}/systemmanage/databaseresource/addDatabaseResource.web";
								form1.submit();
					    	}
					    }
					});
					
				}
			}
	});
	
	$('#butReturn').click(function(){
		parent.document.location.reload();
	    $.fn.closeIssWindow();
	});
	
	$('#butCommon').click(function() {
		var exp = $('#form1').validationEngine('validate');
		if(exp==true)
		{
			showSending();
			$.ajax({
    			type : 'POST',
				url : '${systemctx}/systemmanage/databaseresource/testCommon.json',
				dataType : 'json',
				data: $("#form1").serialize(),
				success : function(data) {
					closeSending();
					if (data.messagetype == '2')
			    	{
						//提示连接失败，则设置为0.
						$.fn.ajaxmessage(data);
						$('#isCommon').val('0');
			    	}else{
			    		//提示连接成功，则设置为1.
			    		$.fn.ajaxmessage(data);
						$('#isCommon').val('1');
			    	}
				}
    		});
		}
	});
	
});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>